import {testNetWork} from "./env"
import { ethers, providers, utils } from "ethers";
export async function findEvent() {
    const main = async () => {
      // 1. 创建provider
      const provider = new ethers.providers.JsonRpcProvider(testNetWork)
      // 2. 创建合约实例
      const addressOrName = '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6'
      const abiWETH = [
        "event Transfer(address indexed from, address indexed to, uint amount)"
      ];
      const contract = new ethers.Contract(addressOrName,abiWETH,provider)
      // 3. 查询合约的事件
      const blockNumber = await provider.getBlockNumber()
      const filterFrom = contract.filters.Transfer();
      const result:any = await contract.queryFilter(filterFrom,blockNumber - 10, blockNumber)
      console.log('resultLength', result.length)
      console.log('info', result[0])
      console.log(`从 ${result[0].args[0]} 转帐 ${ethers.utils.formatEther(result[0].args.amount)}WETH 到 ${result[0].args[1]}`)
    }
    main()
}